/**
 * 与beetl模板的集成
 */
package org.tinyweb.render;

import org.beetl.core.Configuration;
import org.beetl.core.GroupTemplate;
import org.beetl.core.resource.FileResourceLoader;
import org.beetl.ext.web.WebRender;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BeetlRender extends Render{
    
    private static final Logger LOGGER = LoggerFactory.getLogger(BeetlRender.class);
    
    private static GroupTemplate gt = null;
    private static final String CONTENT_TYPE = "text/html;charset=" + getEncoding();
    
    public BeetlRender(String view){
        this.view = view;
    }
    
    public static void init(String webAppRealPath){
        try {
            Configuration cgt = Configuration.defaultConfiguration();
            FileResourceLoader resourceLoader = new FileResourceLoader(webAppRealPath);
            gt = new GroupTemplate(resourceLoader, cgt);
        } catch (Exception e) {
            LOGGER.error(e.getMessage(),e);
        }
    }

    @Override
    public void render() {
        response.setContentType(CONTENT_TYPE);
        WebRender render = new WebRender(gt);
        render.render(view, request, response);
    }
    
}
